package com.xmxsuperstar.http;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class HttpQueryParams {

	private Map<String, List<String>> innerStore = new TreeMap<String, List<String>>();

	public void add(String key, String value) {

		List<String> valueList = innerStore.get(key);
		if (valueList == null) {
			valueList = new ArrayList<String>();
		}

		valueList.add(value);

		Collections.sort(valueList);

		innerStore.put(key, valueList);
	}

	public void addAll(HttpQueryParams otherParams) {
		for (String key : otherParams.getAllKeys()) {
			for (String value : otherParams.get(key)) {
				this.add(key, value);
			}
		}
	}

	public List<String> get(String key) {
		return innerStore.get(key) == null ? new ArrayList<String>()
				: innerStore.get(key);
	}

	public List<String> getAllKeys() {
		List<String> keysList = new ArrayList<String>();
		for (String key : innerStore.keySet()) {
			keysList.add(key);
		}
		Collections.sort(keysList);
		return keysList;
	}

}
